[title]

Computer hardware these days is amazing. It's blindingly fast!

But maybe some of you have

[oldcomputers]

some older hardware at home that you aren't quite ready to throw away.
It's too slow for a modern distro like Ubuntu, or for anything like Windows.

What's the answer?

In this talk, I'll give you some tips that can help you change that
old hardware

[ tortoise ]

from a tortoise

[ racehorse ]

to a racehorse.

[overclocking]
Of course, you can hack your hardware -- experiment with overclocking
and liquid nitrogen cooling.

[explosion]

But that can have drawbacks, too.
I'd like to suggest another approach: slim Linux down so it
doesn't need all those resources in the first place.

Put it on a diet.
[dessert]

Er, wrong kind of diet.
[veggies]

[why-oh-lord]

Why bother?

When I was working on this talk, friends kept asking me,
"Why don't you just buy a new machine?"
And it's a fair question.

[why]
  [cheap]
Well -- okay, it's true -- I'm cheap.
And sometimes there are good reason for being cheap.
You might be outfitting a school's computer lab with donated hardware.
You might be setting up a spare machine for a young relative.
or a public kiosk machine.

  [green]
And even if money's no object, I hate throwing things away!
Adding more lead and other nasty stuff to the ever-growing
pile of e-waste. I'd rather keep old stuff useful!

  [modern machines]
And all of the techniques I'll be talking about are useful even on
fast modern machines. So you have a Core 2 Duo that can boot in 40
seconds. Wouldn't it be better if it booted in 15 seconds?

  [battery life]
If you have a laptop, these techniques will also help you conserve
your battery. Maybe you can go 4 hours instead of 3!

  [educational]
Finally, it's educational. By trimming down your system, you can learn
a lot about how Linux works and where your resources are going.

[what machines]

A lot of you may have "netbooks" -- these new cheap laptops.
I keep seeing reviews that say things like "Netbooks are okay for
checking email, but you can't use them as a real computer."

That's hogwash. Maybe it's true for Windows users, but it isn't
for Linux. Most of what you do on your desktop, you can do on
a netbook just fine ... if you take the time to run an efficient system.

Even an old PII desktop can make a usable machine if you set it up right.

[test-vaio]
I don't actually have a netbook myself. I'm more interested in older
hardware, like PIII laptops and desktops. This is my test machine.

[test-vaio-specs]
It's a Sony Vaio SR17, a Pentium 3 at 700 MHz. It has a video card
that can't do 3D. That turns out to be a problem installing Ubuntu --
their installer can't cope with a non 3D video card, so installing
is a challenge.

  [192 M RAM]
Here's the real catch.  It has 192 meg of RAM. That's not a misprint.
It maxes out at 256.  It's a great machine except for that.
It's light, it's quiet, it has a great keyboard and a good screen.
I don't want to throw away a cool machine like that.

[what-machines-not]
I won't be talking about smartphones or PDAs. You hear a lot of talk
about Android these days, and the line between PDAs and laptops is
getting blurry. Some of these techniques may work for a Linux PDA
or smartphone, but that's not really my focus.

[sections]
I'm going to start with some concrete advice -- tell you a bunch
of things you can do to speed up your machine.

Later in the talk, I'll tell you about how you can analyze your
own machine and find out exactly where the bottlenecks are --
you don't have to take my word for it, you can find out for yourself.

[Lightweight distros]
First, let's talk about lightweight Linux distros.
Should you install a distro that's optimized for speed on
slow computers?

Many of you have probably heard about Xubuntu, the lightweight cousin
to Ubuntu and Kubuntu. It uses the XFCE desktop instead of Gnome or KDE.

But you know what? It's really not very lightweight. Put it on a
netbook or a P3 laptop and it still takes forever to log in or
to do anything.

  [other distros]
Fortunately, there are lots of other choices for lightweight distros.
Puppy Linux, Damn Small Linux, Tiny core, Crunchbang, Debris ... and
new ones are springing up every week or two.

[Puppy]
Puppy is the best of them. It's extremely lightweight, and can run
entirely in RAM (at least if you have a reasonable amount of RAM).

It has an Xvesa option -- that means if you have a tricky graphics
card that X doesn't support very well, you can use a lightweight
X server that works everywhere.

And it can boot from a USB stick -- even on old machines that don't
support booting from USB. There are other distros that say they can
do this, but Puppy is the only one that makes it work well.

[netbook-distros]
What about netbook distros? Every time you turn around there's another
one being announced. Ubuntu has two or three of them, I think, but
they seem to be settling on Ubuntu netbook remix. Intel has Moblin --
there are a couple of Moblin talks this week.

Yhear a lot about Google Android -- what about that?
Well, Android is really designed for much slower machines with
ARM processors, though since it's open source it's been ported to
Intel processors. Still, it's really not designed for this sort
of general-purpose computing.

And that's really the problem with all the netbook distros.
They buy into the hype that netbooks aren't "real" computers,
that they're only good for doing simple stuff.
Pfft to that!

[xubuntu]
But let's get back to Xubuntu. I mentioned it isn't all that light
weight. In fact, it's more resource hungry than some normal distros,
like Debian or Gentoo.

  [challenge]
... that's the challenge! So for most of what I'll be reporting on
here, I started with Xubuntu and put it on a diet. I gradually pared
it down to a much faster and leaner system. Make that mouse run on
his wheel!

[lightweight window managers]
The first step in slimming that distro down is a lightweight window manager.

First, you need to understand the difference between a window manager
and a desktop.

[window manager]

A window manager ... manages your windows. It's the program that puts
frames and titlebars on windows, lets you drag them around and resize
them and change virtual desktops.

[demonstrate]

[desktops]
A desktop, like Gnome or KDE, includes a window manager.
But it also includes lots of other services:
a panel, panel applets, a file manager, and a bunch of daemons,
processes that sit around waiting for things to happen so they
can pop up a window or whatever.

These are all taking up system resources -- precious CPU and memory.
Even if you use a supposedly "lightweight" desktop like XFCE,
they still take a lot of resources.

On a fast system, so what? But if you're on a slow system, you can
gain a lot of performance by ditching your desktop and using only
the services you really need.

[wm 2]
There are lots of window managers to choose from. So many that it
can be hard to choose!

[wm 3]
You can cross out a bunch of them right away -- too slow, too bloated,
too tied to a particular desktop.

But there are still lots of them left!

[wm 4]
This is the "just take my word for it", part of the talk, so I'll
just tell you about my favorite: Openbox.

It's small. It's fast. It's configurable -- you can make it do pretty
much anything you need. And it has a friendly community behind it.

If you do decide to ditch your desktop for a window manager,
but you still want some of the desktop frills like a panel,
or applets, you can mix and match -- there are tons of choices.
Most of them work with any window manager, not just openbox.

By the way, I have the slides from this talk online, along with
a handout that summarizes all the details I'll talk about,
so don't feel like you have to be taking notes.
I'll give you the URL at the end of the talk.

[Application alternatives]
Okay, so you've chosen a window manager. Where else can you get better
performance?

[Word processors]
OpenOffice is probably the biggest application running on most modern
Linux systems. But you don't have to use it.

Abiword and kword are smaller word processors that work pretty well.
They don't have quite as much Microsoft compatibility, so if you need
to trade complicated documents with people using MS Word, they might
not work for you. But if you're just writing documents for yourself --
even if you need to send them to Word users -- they're probably fine.

  [RTF (leafpad)]
If you just need text with markup like bold and italic, a simple
format like RTF might be perfect. There are a few RTF editors
available; Leafpad is a nice lightweight one.

  [HTML]
Or if you already know HTML, you might want to consider using it
to write documents.
It's an open format, everyone can read it, and it will probably
be readable forever, unlike formats like .doc.

  [LyX/Kile]
If you use the TeX document processing system, there are a couple of
word processors based on it: LyX and Kile.
They're great if you already know a little TeX or latex;
otherwise it's probably not worth it.

  [text editor]
But really, ask yourself why you're using a word processor at all.

If you're writing a resume, or something you're going to print out and
hand in for a class, then sure, a word processor is probably the right
tool.

But I see a lot of people using OpenOffice to write notes to
themselves, or, worst of all, to compose email.
DON'T DO THAT! Especially for email -- you'll just end up sending
email that's full of funky characters that don't show up right
on the other end.

If you're doing something that doesn't need fancy formatting,
just use a text editor! You'll have way more software choices --
Linux has tons of great text editors, like vim and emacs, but
also easier to use editors like leafpad, kate, nano, gedit.

Any text editor is way faster and lighter than a word processor,
and you know the format isn't going away -- ever.

[Mail programs]
Mail programs also don't have to be heavyweight. You might be happy
with Thunderbird or Evolution now, but if your mailer ever feels poky
-- if you ever hold that delete key down on a bunch of spam and have
to wait while it finishes -- you might want to try something lighter
weight. I hear sylpheed and balsa are pretty fast.

[Text mail readers]
Or use a text-based mail reader.
The mutt vs pine debate is as classic as Emacs vs. Vim or Gnome vs. KDE.
Pine is a little easier to get started with, if you just want to try
a text mailer to see if it's for you. I'm a mutt user myself, because
I find it's better for the way I like to read mail.

Oh, and by the way, I'm cheating with this slide.
That's a purebred Australian shepherd, hardly a mutt, and those
are redwood trees, not pines.

And I'm cheating even more because it isn't even pine any more --

[Alpine]
they changed their license and renamed it Alpine.

[PDF readers]
If you read PDFs a lot, and you're using Adobe Acrobat Reader,
ditch it! Use PDF or evince. You'll be amazed how much difference
there is, and how much lag you've been getting from acroread.

[Presentation sw]
Okay, what about presentations? You have to use open office for that,
right? It's the only thing that's like Powerpoint!

Well, actually, there are other Powerpoint clones, like kpresenter.
But you don't have to use anything like Powerpoint anyway.

  [xpdf]
For example, you could create your presentation in PDF format and
display it with xpdf. That's a fairly popular way to go.
To create the PDF slides, you can use open office on your big
desktop machine, but there are lots of other packages intended for
creating PDF slides.

  [magicpoint]
There are also several purpose-built presentation tools available,
like magicpoint.
Usually they let you create your slides in a simple text format.

  [HTML]
Or, finally, you can use HTML. That's what I'm doing here. I like
using HTML because I can use a browser to display slides, and then I
can upload the same slides to the web and anyone can view them.

  [but...]
But, displaying HTML brings us to

[elephant]
the elephant in the room that I haven't been talking about...

[Browsers]
Browsers.

Here's a map of my machine's RAM.

I know the text is pretty small ... but
can anyone guess which area represents Firefox?

[Browsers' RAM usage]
And although Firefox is the biggest, the other browsers aren't that
much better. I was hoping Google Chrome might be, but it's still
pretty chunky.

I should mention that this is cheating a little. The blue bars
are actually more important numbers than the red bars. I'll talk
more about memory and how to measure it in the second half of
the talk.

[Browsers' RAM usage 2]
And it doesn't get any better with Firefox 3.5, either.

See the dotted line? That's the physical memory on my little Vaio.

[pig]
*Snort*

[Tiny browsers]
So what can you do about browsers?

If you're really limited on resources, there are some tiny options
available. Of course, there are the text based browsers that don't
even use X: lynx, links, and w3m.

  [dillo]
Dillo's been around a while. It's lightning fast and small, but it
doesn't do CSS or Javascript, so it's not useful for most pages.

There are rumors of a new dillo based on webkit or some more advanced
toolkit, but so far they seem to be just rumors.

  [netsurf]
But netsurf is a real option. It's tiny -- 8 megabytes! -- but it does
some CSS. Don't expect pages to look as good as in Firefox, but
it really does pretty well considering how fast and light it is.

[Small browsers]

But a lot of us need something better than that -- something that
shows the web the same way the big browsers do.

Midori's been around for a while. It's not all that stable, but it's
fairly lightweight.

Kaze ... uh, however you pronounce that, is a newcomer. Again, it's
not all that stable, but keep an eye on it -- it's getting better and
it's very fast.

  [arora]
Arora is a newcomer and it's getting great reviews. Might just be the
lightweight browser to watch.

Most of these small browsers use webkit.
Webkit is the toolkit that Konqueror uses, and konqueror's no lightweight.
Safari, on Macs, also uses webkit, and so does Google chrome.
None of thse browsers are small.

But it turns out the toolkit isn't the problem -- the memory use
comes from all the extra stuff they tack onto it.

  [GtkLauncher]
You can test that by trying the test applications that come with
webkit. GtkLauncher is the test app that comes with the webkit-gtk
library; webbrowser.py is a tiny little Python script that comes with
the python-webkit-gtk bindings. You can use either one of them as a
small, lightweight browser -- or a presentation tool.

So don't assume that just because Firefox takes up 150% of your
machine's memory, all browsers have to be like that. There's hope.
I'll talk a lot more about finding memory hogs later.

Oh, anyone know what that animal is? It's a hyrax -- an animal the
size of a small dog that's the closest living relative to elephants.

[Boot]
But now let's talk about booting.

[boot times]
Ubuntu takes forever to boot!
Just to boot to a console -- forget about X or a desktop --
takes over a minute.

Debian isn't quite as bad, but it still takes over half a minute.

[slug]
Too slow!

[speeding up boot]
How can we speed it up?

[speeding up boot 2]

[modules]
Strangely enough, the number-one thing you can do to speed up booting
is to build a new kernel.

On a typical Ubuntu hardy, you have around 73 modules loaded.

  [1/2 sec]
At last year's Ubuntu developers summit, the kernel developers
revealed that every module you load adds half a second to your boot time.

Think about it.
  [36.5]
That's 36.5 seconds.

And many of those modules will never even get used.

I downloaded a kernel from kernel.org and built it, with no modules,
and just the hardware I had on the machine.

I was amazed. On this laptop I'm using for the presentation, my boot
time went from a minute and five seconds down to 25 seconds. More than
half the boot time was spent loading modules.

On my other machine the difference wasn't nearly as spectacular:
boot time went from 37 seconds to 23 seconds. Still quite a bit faster.

I don't know why the two machines were so different.

Okay, you've built your custom kernel. Or maybe you've decided 
that it's more work than you're willing to go through. I can
understand that. What else can you do?

[cutting services]
Modern distros try to hide the details, but if you enable boot
messages, you'll see stuff like this when you boot.

It's starting all kinds of services during boot. Do we really need
all those services?

[cutting services 2]
No! For instance, what's Avahi? It's some kind of zeroconf protocol
that Macs use. It's also called Rendezvous.
Except I know a lot of Mac users, and none of them use it.
I wanted to test it once, for an article, and I went around asking all
my Mac-using friends, and I couldn't find anyone who had a running
Rendezvous setup where I could bring my laptop and test.

So why is it there slowing down my boot?

CPUFreq -- well, that sounds great. Except I don't own a machine where
those services actually work.

I have SpamAssassin installed because I use it with Procmail. But why
is it doing anything at boot time?

CUPS and exim or postfix are useful services. But if I'm on a laptop,
where I'm not going to print or receive any mail, why do I need to be
running them?

You may use NetworkManager on your laptop. I don't, because it doesn't
work very well if you're not running a desktop like Gnome. But I
certainly don't need it on my desktop, which always has the same
network address and doesn't have wireless.

I use apache, even on my laptop, since I do web development. But that
doesn't mean I want to run a web server every single time I boot.
If I'm going to do some web development that needs a server, I can
start apache by hand.

And so on, you get the idea. It's easy to cut out services that
don't need to be there.

Maybe we can even cut more ...

[cutting services 3]
dbus is actually useful, but you might find you're not using it for much.

hal -- well, I'll get to that shortly.

gdm: That's the thing that makes your system boot into a pretty login screen.
I don't actually find it very useful, though.

You get the idea. If you want a fast boot, be brutal and cut out any
service ou don't really need.

[Disabling init scripts]
Okay, it's easy enough to cross out lines of text. How do you actually
prevent those services from running?

Of course, you can uninstall them. I uninstall a lot of services like
avahi and gdm that I know I won't be using.

But what about services like apache or postfix, that you want
sometimes but not all the time?

They're controlled by files in /etc/init.d.

  [chkconfig]
On Redhat, disabling them is dead simple. chkconfig servicename off
and you're done.

  [update-rc.d]
Unfortunately, Debian doesn't use chkconfig -- they've replaced it
with something called update-rc.d that's a lot less useful.
You can remove services, but you can't temporarily disable them.

  [insserv]
Ubuntu also has a package called chkconfig. If you install it,
you'll find that it depends a program called insserv. Unfortunately,
insserv doesn't work if there are any loops -- if there's any case
where service a depends on service b, but b depends on a.

And Ubuntu has loops. So you can install insserv, but it doesn't work,
and neither does chkconfig.

[Disabling init.d files]
So how DO you disable a file? Here's the official Debian answer.

First, you find your runlevel. On Ubuntu it'll probably be 2.

Then go to the rc.d file corresponding to that runlevel -- if it's
2, go to /etc/rc2.d.

As root, find the file corresponding to the service you want to turn
off -- let's say it's apache2 -- and rename the file so that it starts
with a capital K rather than a capital S.

Clear, huh?

[noinit.d]
If, like me, you can never remember the Kays and Esses, here's another
way. Make a directory called /etc/noinit.d. Then when you want to
disable apache2, just move the script named apache2 from init.d to noinit.d.

If you want to start apache by hand, just run it from noinit.d.

[Stuff you don't need]
It's easy to turn off services, so watch your boot messages and see
what's taking a long time. And look at the services currently
installed in /etc/init.d and think about whether you need them.
Are you using apparmor, or is it just there because Ubuntu sticks
it there by default? Do you have Bluetooth hardware and use it
a lot? PPP is used for modems -- does that need to be running?
WPA is security for wireless networks -- why is that running on
a desktop that doesn't even have a wireless card?

[Init scripts to disable]
Here are some more suggestions.

[ INSERT LONG LIST OF INIT SCRIPT SLIDES ]

[Solid state disks]
Another way of speeding up your system -- either at boot time or later
-- is a solid-state disk.

SSDs are MUCH faster at reading. You can cut your boot speed in half
by switching to an SSD.

The down side is that they're expensive for the same amount of disk
space. But you can get a small SSD and use it for your system
directories -- you only need a few gigabytes for that.
Then put your big files -- your home directory -- on a regular hard drive.

Of course, that doesn't work so well for laptops that have only one drive.
But if you have an old laptop that you want to speed up, it's worth
considering switching to a small solid-state drive. You can put your
old drive in an external USB case and still have access to all your
data, but meanwhile your basic system will run like a greyhound.

[Find out]
Don't want to take my word on any of this? Let's talk about how you
can analyze your system and find out for yourself where the
bottlenecks are.

[Bootlogd]
When you're looking at your init scripts, you might notice one
called bootlogd.

Wouldn't it be useful to have a list of everything that runs during
boot and how long each one takes?

That's what bootlogd does. There's a file called /etc/default/bootlogd
where you can turn it on.

[Bootlogd on Ubuntu]
... Unfortunately, it's broken on Ubuntu. The problem has something to
do with using Upstart instead of sysvinit.

Someone filed a bug on bootlogd a couple releases back.
It turns out that it's somewhat tricky to fix it, though there
are patches floating around that work for some people.

So someone asked in the bug, "If you can't fix it, why are the
files for it still there?"

The answer was that since some people have been able to take bootlog,
patch the source and get it working, if they remove the files it might
break those people.

Really! I'm not making that up! Go read the bug for yourself --
the link is in the handout.

[fsck]
File System Check. That's the thing that looks through your disks
every so often to make sure they don't have errors.

  [well, sometimes]
My husband calls it "winning the fsck lottery".  Yyou think you're
just going to boot your system and immdiately start using it,
and you find out that oops, this is the time you're going to have to
wait 5 minutes for it to check your disk.

[fsck off]
But you can control that. First, you can adjust how often it happens:
either by making the count bigger -- say, fsck every 50 times instead
of every 30 -- or by setting it to fsck once a month.

  [fstab]
Or you can turn fsck off entirely, by setting the last field in
/etc/fstab to zero.

[when to fsck]
Wait -- but that means you'd never check your disks!

Not everyone agrees whether you need to fsck ext3 or not. You can
probably just never fsck and get away with it.

I'm not recommending that: don't come crying to me. Safer is to check
how long it's been, and decide on that basis.

[showfsck]
You can find out how close a filesystem is to its next check by
running the showfsck program. You have to be root or use sudo.

You can turn off checking in your fstab file, then use showfsck to
tell you when it's a good time to check.

That way you don't have a rude shock when you expect to be able to
boot and can't.

[other fsck checks]
If showfsck doesn't work for you, you can use dumpe2fs to do the same thing.
It can also tell you a bunch of other useful information about your disk.

  [autofsck]
If you want to automate it, there's a program called autofsck that
prompts you at logout about whether you want to run it before shutting
down. It only works if you're running gdm.

[Performance Tools]

There are several tools that will show you how busy your system is.
Conky seems popular, but I found it hard to use. I like xosview better
-- it's not all that pretty but it works really well and it's easy
to configure. If you're using a Gnome desktop, you can use
gnome-system-monitor.

But I'm going to talk more about command-line utilitiesl

[top]
You've probably seen top. It updates every second or two, keeping you
up to date on what's using the most CPU on your system. It tells
you a bit about memory, too -- those VIRT, RES, and SHR columns.
I'll be talking more about memory later in the talk.

[topflags]
Normally, top runs interactively, but you can run it in "batch" mode
too. -b tells it just to dump its output without trying to be smart
about where it draws it in the terminal window, and -n 1 tells it
to run once then exit.

You can also make it sort by memory or by total CPU time instead of
by the amount of CPU it's currently using.

[ps axu]
top is great for quick checks of what's occupying the system, but the
real workhorse is ps. That stands for process status, and it tells you
all sorts of things about what's running on your system.

axu is a good set of flags to pass to it -- a means all processes,
and x means "really all processes" -- even processes that aren't
attached to a terminal. The x is important because it lets you see
daemons like apache and acpid that might be taking up time.

u means "user format" -- it basically specifies a standard set of
useful columns.

But those columns are a little confusing -- and worse, it sorts by
process id, not by anything useful. Notice how the processes at the
top are taking up zero CPU and memory, then when you look farther down
in the list you start seeing processes that are actually doing
something? And the ones I care about -- like gimp or firefox --
are way down where I'd have to search for them.

[man ps]
So you read the ps manual page to find out how to sort it in some
smarter way. And there are lots of options! There's a --sort option
where you can pass it things like -pmem to start with the processes
that are taking up the most memory.

  [Unfortunately]
Unfortunately, --sort doesn't work, and judging by what I see in
google, it hasn't worked in a long time.

[what does work]
But never fear -- that ps man page is 1147 lines, so there's got to be
something there for us. And so there is. Capital O is a sort that
actually does work. You'll find it in the man page under OBSOLETE SORT
KEYS. -C to sort by CPU, r for rss and v for virtual size.

[controlling ps]
You can also control which fields ps shows, so you don't get lines so
long they don't fit in your terminal window. Here's a useful ps
command that sorts by CPU and shows fields that are typically useful.

Don't write that down! I'll have the slides for this talk online,
along with a handout that lists a few useful tips like this one.

[Powertop]
Another fabulous performance tool is Powertop. This was developed by
IBM a couple of years ago to help Linux laptops last longer when
running on batteries. It's a little like top, in that it runs
interactively in the terminal and refreshes every few seconds.
Some of the information it prints may seem arcane -- what's
hrtimer_start_range_hs and what can you do about it, anyway?

But the best part of Powertop is down at the bottom of the screen,
where it gives you suggestions for fixing programs that are taking
up too much CPU or waking your machine up too often.

Here, it's telling me that a program called hal is polling my CDROM
drive frequently. That means it's waking up a couple of times a second
to say "have you inserted a CD? Have you inserted a CD? Have you
inserted a CD?" so that in case it ever finds a CD, it'll be ready
to jump in and mount it.

Now, I don't know about you, but I usually know when I've inserted a
CD, and I'm perfectly capable of mounting it myself. I don't want some
program sitting around using up power and CPU checking for things like
that. And hal doesn't just check the CD drive -- it also checks USB
devices, so if you have one of those 5-in-one flash card readers,
you've got hal checking the CD drive, the SD drive, compact flash,
memory stick and so on. Total waste of resources.

But the greatest thing about powertop is that it gives me a suggestion
on how to stop hal from doing that. It gives me this hal-disable-polling
command that I can put in /etc/rc.local -- or if I want to, I can kill
the hald-addon-storage process from powertop directly just by typing k.

If I do type a k to kill hal, powertop will look for the next offender
and offer me a suggestion about that. I love powertop. Powertop is awesome.

[Kill-a-Watt]
As long as I'm talking about power, if you care about power and you
don't already have a Kill-a-Watt, get one. They're about 20 bucks at
Fry's or online, and they can help you figure out how efficient your
system is.

There's lots more to say about power saving, but that's a whole nuther
talk. Maybe next year.

[Bootchart]
Another fun program is bootchart, which tells you where your system is
spending time while it's booting.

It can be a little tricky to set up.

Ubuntu has a package for it, but it only works if you're running their
kernel (with all the modules).

Otherwise, you have to fiddle with grub entries to get it to make a
data file, then download a Java app to post-process the data file.

Kind of a hassle but it's fun to look at the output. 

[iostat and hdparm]
How fast are your disk drives? iostat and hdparm can tell you whether
they're performing as well as you expect. On an older IDE based
system, you can get surprises, like finding out your disk isn't
using DMA when it should.

[Memory]
What about memory tools? How do you keep track of which applications
are taking up all your system's memory, anyway?

[Memory tools]
I showed you this screenshot earlier -- it's from a program called
gmemusage. That's a neat little program based on an old SGI program
called bloatview. Bloatview was an amazing program. gmemusage has
some problems, but it's a nice fast way of getting a snapshot of where
your RAM is going.

Unfortunately, on the latest Ubuntu, jaunty, it's broken. But there's
a patch (I actually submitted it, while I was doing research for this
talk) so with any luck they'll fix it in the next release. Or if you
don't want to wait, send me mail and I'll help you get it working.

Of course, there are also some well-known commandline programs like
ps, top, free and vmstat.

[ps -axu]
Like ps axu. (No, you don't need a minus before the axu.)

It gives you a bunch of memory columns: %MEM, VSZ, RSS.
What do they all mean?

[memory in ps]
Vsize is the "virtual size" -- the total size of the process including
all code, data, libraries, everything.

Resident Set Size is the amount of memory the program is currently
taking up in your computer's RAM, not including anything that's
swapped to disk.

ps also has a third number it can report, Size, which means -- well,
actually nobody's quite sure what it means. You should probably ignore SZ.

But wait -- remember that browser graph I posted earlier?

[Browsers' RAM usage 3]
Here it is again. Firefox's virtual size is around 265 to 300 megabytes.
Its resident set size is 110M.
But this was on my desktop machine -- and it wasn't using any swap!
Everything was in memory. So why aren't vsize and rss the same?

[vsz != rss]
It turns out that memory can be allocated -- sort of -- but not really used.

What happens is that Firefox says "I might be using a lot of memory
eventually, so allocate a big block of space for me." But instead of
actually grabbing that space from RAM, it uses something called mmap
to tell the system "if I try to access this memory, create it then."

Most of that memory never does end up being used -- it's anyone's
guess why Firefox allocates it -- so it doesn't actually load down
the system or take memory away from other processes.

Okay, so RSS is a more useful number than Vsize.

[not the whole story]
But that's not the whole story either. See, some of that memory is in
shared libraries: libraries that potentially can be used by lots of
different programs.

  [don't count]
Application programmers will tell you, "You can't rely on ps to tell
you that an app is bloated! You're completely ignorant and stupid if
you believe those numbers! Shared libraries don't count against a
program's memory usage!"

Let me tell you what *I* think of that ...

[Quetzy]
It's largely BS.

You may wonder what this slide is.
Did someone really make a sculpture of, well, BS?

This is San Jose's famous statue of Quetalcoatl by Robert Graham.
The fearsome Feathered Serpent, the Aztec God of the Sky!

Also known as "the giant cow turd", or "the Poop Snake".

San Jose commissioned it. It cost $500,000.
It sits in Caesar Chavez plaza, about two blocks that way.
Be sure to visit Quetzy while you're in town.
We're very proud of our Poop Snake.

But back to shared libraries.

[shlibs]
But it depends on you, and what apps you're actually running.

If you have a shared library that's taking up memory, the important
question is, How many apps are using that library?

  [gtk/qt]
If you're running a Gnome or KDE desktop, and the library is gtk or
qt, then you might have lots of apps all using the same toolkit.

  [firefox/OO]
On the other hand, if we're talking about Firefox or Open Office
libraries, the answer is probably: 1.

We all love the idea of having lots of varied apps built on the
Mozilla platform, using XUL and sharing code with Firefox.

The reality? How many people here use chatzilla or songbird or some
other mozilla-based app?

If your hand is only up because you use both Thunderbird and Firefox,
put your hand down.

You might be thinking, "But I use both firefox and thunderbird!" Great
-- but last I heard, those still don't share libraries. So you get two
sets of mozilla libraries instead of just one!

[useful memory tools]
So, this is terrible! None of the standard apps for showing memory
use actually gives us numbers that are very useful.
What *can* you use?

Well, in /proc there are a bunch of files you can decode to give
you better memory numbers, like statm.

  [exmap]
There's a useful program called exmap you can download, but it
requires a kernel module.

  [ps_mem.py]
There's a great script called ps_mem.py that gives you much better
numbers than ps does. Google for it, or you can find a link in the
handout that I'll upload along with these talk slides.

  [pmap -d]
Finally, there's pmap -d.

[pmap -d pid]
Run it with a process ID, and it gives you pages of gobbledygook --
and at the end it tells you how much memory the process is taking, how
much of it is private and how much is shared libraries.

Of course, that's complicated and it still doesn't tell you whether
the shared libraries are being used by more than one process.
So, basically ...

[complicated]
Memory is complicated!
The more I looked into it, the more I realized that there's really a
whole separate talk there.

So come back next year and maybe I'll have some much more useful
answers for you about memory.

Meanwhile, what do you do if you need memory answers now?

[free.html]
Simple programs like free or vmstat just tell you how much memory
the whole system is using.

What good is that?

Run free right after you log in and note the total.
Then run firefox, load a few web pages -- and run free again.
The difference is how much Firefox is using.

But wait! That's not the whole story either.

[readahead]
See, modern distros do this thing called Readahead.
It preloads files.
Lots of files.
Specifically, 710 at boot time, plus 281 more when you run a desktop.
(That's on xubuntu -- it may be worse on Gnome.)

That can be useful. The idea is that you trade off boot speed for
speed later. So you slow down your boot reading in a bunch of gtk
library files, and later, when you run GIMP, it starts up faster
because those files have already been loaded.

But that assumes you really are going to use all the files it loads.
If you aren't, it's just a waste of time.

So if you're using free to find out how much memory an app is using,
if readahead is already preloading libraries that the app uses then
free won't tell you much.

You can turn off the readahead service -- I'll talk about that in a
minute -- or edit /etc/readahead to control which files are preloaded.

[Summary]
Oh, wait, that's how YOU can slim down, not your system.

[Real summary]
So, I've covered a lot of ground here.

You can go straight to a lightweight distro like Puppy and see if they
got it right, or you can stick with your current distro but switch
to lighter weight window managers and applications.

You can speed up your boot by building a custom kernel without modules,
by cutting services, and by skipping fsck.

You can speed up everything by using a solid-state disk -- a way to
give new life to an old slow system.

And I've given you a long list of tools you can use to figure out
where your performance issues are.

That's it! I've put up a cheat sheet and a copy of the slides
at shallowsky.com/featherweight, so if you need any details I
raced past, you can get them there.

Thanks for listening!  Are there any questions?

